package gui;

import interfaces.BankRegistry;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import testit.GUITest;
import banking.BankImpl;

public class GUIaccountStatement extends JFrame {
	
	JTextField textfield_accountNumber;
	JTextField textfield_mimeType;
	JTextField textfield_output;
	
	JButton	button_accountStatement;
	
	JLabel label_accountNumber;
	JLabel label_value;
	
	public GUIaccountStatement() {

		this.getContentPane().setLayout(null);

		this.transferMoneyWindow();

		this.addWindowListener(new WindowListener() {

			public void windowClosed(WindowEvent arg0) {
			}

			public void windowActivated(WindowEvent e) {
			}

			public void windowClosing(WindowEvent e) {
				
			}
			
			public void windowDeactivated(WindowEvent e) {
			}

			public void windowDeiconified(WindowEvent e) {
			}

			public void windowIconified(WindowEvent e) {
			}

			public void windowOpened(WindowEvent e) {
			}
		});

	}
	
	public void transferMoneyWindow() 
	{

		// new instance
		textfield_accountNumber = new JTextField();
		textfield_output = new JTextField();
		
		button_accountStatement = new JButton("Account: Value");
		
		
		label_accountNumber = new JLabel("Account Number:");
		label_value = new JLabel("Value: ");
		
		//Action Listener
		button_accountStatement.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				try {
					transferMoney();
				} catch (Exception e) {
					e.printStackTrace();
				}
				
			}

		});
		
		// position 
		textfield_accountNumber.setBounds(150, 40, 200, 25);
		textfield_output.setBounds(10, 140, 400, 25);
		
		button_accountStatement.setBounds(75, 240, 200, 30);
		
		label_accountNumber.setBounds(10, 40, 150, 25);
		label_value.setBounds(10, 120, 150, 25);
		
		
		
		// add window
		this.getContentPane().add(textfield_accountNumber);
		this.getContentPane().add(textfield_output);
		
		this.getContentPane().add(button_accountStatement);
		
		this.getContentPane().add(label_accountNumber);
		this.getContentPane().add(label_value);

		this.pack();
	}

	public void transferMoney() throws Exception{
		// take params and call method
		int	accountNumber = Integer.parseInt(textfield_accountNumber.getText());
		BankImpl Sparkasse = BankRegistry.loockup("Sparkasse");
		textfield_output.setText(Sparkasse.showAccountValue(accountNumber));
	}
}